#include <iostream>
using namespace std;
const int N = 100001;

using ll =  long long;
ll arr[N];
int main() 
{
    int n  = 0;
    cin>>n;
    for(int i = 1;i<=n;i++)
    {
        cin>>arr[i];
    }
    ll mp = 0;
    for(int i = n-2;i>0;i--)
    {
        int k = min(arr[i],min(arr[i+1]/2,arr[i+2]/3));
        mp+=5*k;
        arr[i]-=k;
        arr[i+1]-=2*k;
        arr[i+2]-=3*k;   
    }
    for(int i = 1;i<=n;i++)
    {
        mp+=arr[i];
    }
    cout<<mp<<endl;
}
// 64 位输出请用 printf("%lld")